package com.ciwong.epaper.modules.viedoexplantion;

import android.view.View;
import android.view.ViewGroup;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.viedoexplantion.bean.BigViedoQuestion;
import com.ciwong.epaper.modules.viedoexplantion.bean.SmallViedoQuestion;
import com.ciwong.epaper.modules.viedoexplantion.bean.ViedoExplantion;
import com.ciwong.mobilelib.ui.BaseActivity;

import java.util.List;

/**
 * Created by young on 2016/7/5.
 * 视频解析类
 */
public class ViedoExplationActivity extends BaseActivity {
    private ViewGroup container;
    private ViedoExplantion viedoExplantion;
    //试卷名称
    private String title;
    //大题列表
    private List<BigViedoQuestion> bigViedoQuestions;
    //大题模型
    private BigViedoQuestion bigViedoQuestion;
    //大题题干
    //大题图片
    //小题列表
    private List<SmallViedoQuestion> smallViedoQuestions;
    //子题列表
    private List<SmallViedoQuestion> childViedoQuestions;



    @Override
    protected int setView() {
        return R.layout.activity_viedo_explantion;
    }

    @Override
    protected void findViews()
    {
        container=(ViewGroup) findViewById(R.id.viedo_explantion_lay);
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void init() {


    }

    @Override
    protected void loadData() {
        //测试代码
       viedoExplantion= ViedoTest.getViedoExplantion();

//        loadUi();
        //视频讲解测试代码
        TestLoadUi();

    }
    /**
     * 题型测试方法
     *
     */
    public void TestLoadUi(){
        View view;

        view= LoadUiImp.loadLayout(bigViedoQuestion,QuestionType.QUESTION_TYPE_CHOICE,ViedoExplationActivity.this,true);
        container.addView(view);
        view= LoadUiImp.loadLayout(bigViedoQuestion,QuestionType.QUESTION_TYPE_ChooseMore,ViedoExplationActivity.this,true);
        container.addView(view);


//        view= LoadUiImp.loadLayout(bigViedoQuestion,QuestionType.QUESTION_TYPE_FILL_CLOSE_BLANK,ViedoExplationActivity.this);
//        container.addView(view);


        view= LoadUiImp.loadLayout(bigViedoQuestion,QuestionType.QUESTION_TYPE_FILL_CLOSE_BLANK,ViedoExplationActivity.this,true);
        container.addView(view);
        view= LoadUiImp.loadLayout(bigViedoQuestion,QuestionType.QUESTION_TYPE_READ,ViedoExplationActivity.this,true);
        container.addView(view);
       view= LoadUiImp.loadLayout(bigViedoQuestion,QuestionType.QUESTION_TYPE_SHORT,ViedoExplationActivity.this,true);
        container.addView(view);



//        view= LoadUiImp.loadLayout(bigViedoQuestion,QuestionType.QUESTION_TYPE_GRAMMAR_BLANK,ViedoExplationActivity.this);
//        container.addView(view);
 }


    /**
     * 对试卷进行解析加载
     */
    public void loadUi(){
        View view;
        Boolean bo=false;
        if(viedoExplantion!=null){
            //试卷名称
            title=viedoExplantion.getTitle();
            //取得大题列表
            bigViedoQuestions=viedoExplantion.getBigViedoQuestions();

            if(bigViedoQuestions!=null){
                for (BigViedoQuestion bigViedoQuestion:bigViedoQuestions){
                    //加载大题题干和图片
                 view= LoadUiImp.loadLayout(bigViedoQuestion,QuestionType.QUESTION_TYPE_Title,ViedoExplationActivity.this,true);//大题题干都显示序号
                    container.addView(view);
                    //得到小题列表
                    smallViedoQuestions=bigViedoQuestion.getSmallViedoQuestions();
                    if(smallViedoQuestions.size()>1){
                        //大于1则显示序号
                        bo=true;
                    }else {
                        //不显示序号
                        bo=false;
                    }

                    if(smallViedoQuestions!=null){
                        for (SmallViedoQuestion smallViedoQuestion:smallViedoQuestions){
                            int type=smallViedoQuestion.getQtype();
                            //加载小题题干和资源
                            view=LoadUiImp.loadLayout(smallViedoQuestion,type,ViedoExplationActivity.this,bo);
                            container.addView(view);
                            //得到子题列表
                            childViedoQuestions=smallViedoQuestion.getSmallViedoQuestions();
                           if(childViedoQuestions!=null){
                               for(SmallViedoQuestion smallViedoQuestion1:childViedoQuestions){
                                   int typ=smallViedoQuestion1.getQtype();
                                   view=LoadUiImp.loadLayout(smallViedoQuestion1,typ,ViedoExplationActivity.this,true);
                                   container.addView(view);
                               }
                           }
                        }
                    }
                }
            }
        }
    }


}
